package com.zbkj.crmeb.user.controller;

import com.common.CommonPage;
import com.common.CommonResult;
import com.common.PageParamRequest;
import com.google.common.collect.Lists;
import com.zbkj.crmeb.user.model.UserLevelGood;
import com.zbkj.crmeb.user.model.UserMark;
import com.zbkj.crmeb.user.model.UserMarkEnum;
import com.zbkj.crmeb.user.request.UserSearchRequest;
import com.zbkj.crmeb.user.response.UserResponse;
import com.zbkj.crmeb.user.service.UserLevelGoodService;
import com.zbkj.crmeb.user.service.UserMarkService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 用户标记记录表 前端控制器
 * +----------------------------------------------------------------------
 * | CRMEB [ CRMEB赋能开发者，助力企业发展 ]
 * +----------------------------------------------------------------------
 * | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
 * +----------------------------------------------------------------------
 * | Licensed CRMEB并不是自由软件，未经许可不能去掉CRMEB相关版权
 * +----------------------------------------------------------------------
 * | Author: CRMEB Team <admin@crmeb.com>
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/user/mark")
@Api(tags = "会员 -- 标记")
public class UserMarkController {

    @Autowired
    private UserMarkService userMarkService;

    @Autowired
    private UserLevelGoodService userLevelGoodService;

    /**
     * 标记列表
     */
    @ApiOperation(value = "列表")
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public CommonResult<List<UserMark>> getList() {
        List<UserMark> markList = Lists.newArrayList();
        for (UserMarkEnum c : UserMarkEnum.values()) {
            markList.add(new UserMark().setId(c.getIndex()).setMarkName(c.getName()));
        }
        return CommonResult.success(markList);
    }

    /**
     * 修改用户标记
     */
    @ApiOperation(value = "修改用户标记")
    @RequestMapping(value = "/updateUserMark", method = RequestMethod.GET)
    public CommonResult<String> updateUserMark(@RequestParam("userId") Integer userId, @RequestParam("markId") Integer markId) {
        UserLevelGood userLevelGood=userLevelGoodService.getById(markId);
        userMarkService.updateUserMark(userId, userLevelGood);
        return CommonResult.success();
    }
}



